﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using FlickrSample.SL.Infrastructure.Flickr.Commands;
using FlickrSample.SL.Infrastructure.Flickr.Entities;
using FlickrSample.SL.Infrastructure.Flickr.Parser;

namespace FlickrSample.SL.Infrastructure.Repo.Photo.Online
{
    public class PhotoRepo : IPhotoRepo
    {
        public void GetSizes(FlickrPhoto photo, Action callback)
        {
            var command = new flickr_photos_getSizes(photo.PhotoId);
            ServiceLocator.FlickrRepo.ExecuteCommand(command, result =>
            {
                if (!string.IsNullOrEmpty(result))
                {
                    var instances = PhotoParser.ParseInstances(photo, result);
                    photo.PhotoInstances = instances;
                }

                callback();
            });
        }

        public void GetPhotos(PhotoSet set, Action<List<FlickrPhoto>> callback)
        {
            var command = new flickr_photosets_getPhotos(set.Id);
            ServiceLocator.FlickrRepo.ExecuteCommand(command, result =>
            {
                if (!string.IsNullOrEmpty(result))
                {
                    var sets = PhotoParser.ParsePhoto(result);
                    callback(sets);
                }
                else
                {
                    callback(null);
                }

            });

        }
    }
}
